#include <stdbool.h>
#include "bsp/bsp_drivers.h"
#include "controller/motor.h"


void ADC_IRQHandler(void)
{
	adc_wait_clear_inj_chans();
	motor_adc_irq_handler(motor(0));
}

void PWM_Update_IrqHandler(void) {
	if (timer_wait_clear_update()) {
		timer_up_irq_handler(motor(0));
	}
}

void PWM_Brk_IrqHandler(void) {
	if (timer_wait_clear_brk()) {
		mc_fault_irq_handler(motor(0));
	}
}
#ifdef MAG_ENC_Z_IrqHandler
void MAG_ENC_Z_IrqHandler(void) {
	if (timer_enc_z_wait_clear()) {
		encoder_abi_irq_handler(&motor(0)->encoder, timer_enc_z_cap_value());
	}
}
#endif

void MC_1MS_IrqHandler(void) {
	if (timer_sch_update()){
		mc_sched_irq_handler(motor(0));
	}
}

void DRV8301_Fault_IrqHandler(void) {
	mc_fault_irq_handler(motor(0));
}

#if (CONFIG_USBOTG_DEVICE)
extern PCD_HandleTypeDef hpcd_USB_OTG_FS;
void OTG_FS_IRQHandler(void) {
    HAL_PCD_IRQHandler(&hpcd_USB_OTG_FS);
}
#endif

#ifdef CONFIG_SPI_DEV
void DMA1_Stream0_IRQHandler(void)
{
  HAL_DMA_IRQHandler(&hdma_spi3_rx);
}

void DMA1_Stream7_IRQHandler(void)
{
  HAL_DMA_IRQHandler(&hdma_spi3_tx);
}
#endif
